package com.sfac.springboot.modules.common.service.impl;

import com.sfac.springboot.modules.common.dao.ExceptionLogDao;
import com.sfac.springboot.modules.common.entity.ExceptionLog;
import com.sfac.springboot.modules.common.service.ExceptionLogService;
import com.sfac.springboot.modules.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * @author jzq
 * @date 2022/8/25 10:02
 */
@SuppressWarnings({"all"})
@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {

    @Autowired
    private ExceptionLogDao exceptionLogDao;


    @Override
    @Transactional
    public Result<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {
        ExceptionLog temp = exceptionLogDao.getELByPathAndName(
                exceptionLog.getPath(),
                exceptionLog.getExceptionType());

        if (temp != null) {
            return new Result<ExceptionLog>(Result.ResultStatus.FAILED.code,
                    "异常信息已存在");
        }

        exceptionLog.setCreateDate(LocalDateTime.now());
        exceptionLog.setUpdateDate(LocalDateTime.now());
        exceptionLogDao.insertExceptionLog(exceptionLog);

        return new Result<ExceptionLog>(Result.ResultStatus.SUCCESS.code,
                "插入成功", exceptionLog);
    }

}
